<template>
  <div class="app-container">
      <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
    <div id="myChart" style="width: 800px;height:500px;"></div>
    <!-- {{list[0].count}} -->
  </div>
</template>

<script>
import statistics from '@/api/statistics'
export default {
  name: 'hello',
  data () {
    return {
      list:[{}],//数据集合
      msg: 'Welcome to Your Vue.js App'
    }
  },
  created() { //在页面渲染之前执行
    //一般调用methods定义的方法，得到数据
       this.getList()
    },
  mounted(){
    // this.drawLine();
  },
  methods: {
    getList(){
            statistics.getStatistics()
            .then(response => { //请求成功response是接口返回数据
            //返回集合赋值list
                this.list = response.data
                this.drawLine()
                console.log(this.list[0].count)
                //总记录数
                // this.total = response.data.total
                // console.log(response.data)
            })//请求成功
            .catch(error => {//请求失败
                console,log(error)
            })//请求失败
          
        },
    drawLine(){
        // 基于准备好的dom，初始化echarts实例
        let myChart = this.$echarts.init(document.getElementById('myChart'))
        // 绘制图表
        myChart.setOption({
            title: { text: '2022年预约订单统计条形图' },
            tooltip: {},
            xAxis: {
                data: ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: [this.list[0].count, 
                this.list[1].count, 
                this.list[2].count, 
                this.list[3].count, 
                this.list[4].count, 
                this.list[5].count,
                this.list[6].count,
                this.list[7].count,
                this.list[8].count,
                this.list[9].count,
                this.list[10].count,
                this.list[11].count]
            }]
        });
    }
  }
}
</script>

<style>

</style>